package com.kitchen.common.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class QfsyBeanUtils {

    public static <T,V> List<V> castToVoList(List<T> sourceList, Class<V> vClass){
        final ArrayList<V> targetList = new ArrayList<>();
        for (T t : sourceList) {
//            final V v = new V();
            try {
                final V v = vClass.newInstance();
                BeanUtils.copyProperties(t,v);
                targetList.add(v);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
        return targetList;
    }
    public static <T,V> List<V> castToVoList(T sourceList, Class<V> vClass){
        final ArrayList<V> targetList = new ArrayList<>();
            try {
                final V v = vClass.newInstance();
                BeanUtils.copyProperties(sourceList,v);
                targetList.add(v);
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        return targetList;
    }
}
